﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using MyFramework.Helper;
using Newtonsoft.Json.Linq;

namespace learncore2.Controllers
{
    [ApiVersion("1.0")]
    [Route("api/v{version:apiVersion}/[controller]/[action]")]
    public class ValuesController : Controller
    {
        [HttpGet]
        public static async Task<JObject> GetJsonAsync(Uri uri)
        {
            using (var client = new HttpClient())
            {
                var jsonString = await client.GetStringAsync(uri);
                return JObject.Parse(jsonString);
            }
        }
        [HttpPost]
        public string GetAESKey()
        {
            return EncryptHelper.GetAESKEY();
        }
        // GET api/values
        [HttpGet]
        public async Task<string>  Get()
        {
            var jsonTask = await GetJsonAsync(new Uri("https://www.distnsrs.cn/login/getguid"));
            return jsonTask.ToString();
        }

        // GET api/values/5
        [HttpGet("{id}")]
        public string Get(int id)
        {
            return "value:"+id;
        }

        // POST api/values
        [HttpPost]
        public void Post([FromBody]string value)
        {
        }

        // PUT api/values/5
        [HttpPut("{id}")]
        public void Put(int id, [FromBody]string value)
        {
        }

        // DELETE api/values/5
        [HttpDelete("{id}")]
        public void Delete(int id)
        {
        }
    }
}
